package com.ccp.dev.workflow.configuration;

import com.ccp.dev.workflow.bpmutil.FlowableIdGenerator;
import org.flowable.spring.SpringProcessEngineConfiguration;
import org.flowable.spring.boot.EngineConfigurationConfigurer;
import org.springframework.context.annotation.Configuration;

import java.sql.DatabaseMetaData;
import java.sql.SQLException;

/**
 * ClassDescribe:flowable配置类
 *
 * @author :jiayueqiao
 * Date: 2019-05-10
 * Since:1
 * To change this template use File | Settings | File Templates.
 */
@Configuration
public class FlowableConfiguration implements EngineConfigurationConfigurer<SpringProcessEngineConfiguration> {

    private static String GABSE_NAME="GBase";

    @Override
    public void configure(SpringProcessEngineConfiguration springProcessEngineConfiguration) {
        //适配南大通用数据库
        DatabaseMetaData databaseMetaData = null;
        try {
            databaseMetaData = springProcessEngineConfiguration.getDataSource().getConnection().getMetaData();
            String databaseProductName = databaseMetaData.getDatabaseProductName();
            if(GABSE_NAME.equals(databaseProductName)){
                springProcessEngineConfiguration.setDatabaseType("mysql");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        springProcessEngineConfiguration.setIdGenerator(new FlowableIdGenerator());
    }

}
